package com.dwx.guli.service.trade.service.impl;

import com.dwx.guli.service.trade.entity.PayLog;
import com.dwx.guli.service.trade.mapper.PayLogMapper;
import com.dwx.guli.service.trade.service.PayLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 支付日志表 服务实现类
 * </p>
 *
 * @author dwx
 * @since 2021-07-18
 */
@Service
public class PayLogServiceImpl extends ServiceImpl<PayLogMapper, PayLog> implements PayLogService {

    @Override
    public void createPayLog(Map<String, String> notifyMap) {
        String tradeNo = notifyMap.get("out_trade_no");
        PayLog payLog = new PayLog();
        payLog.setOrderNo(tradeNo);
        payLog.setTotalFee(Long.parseLong(notifyMap.get("total_fee")));
        payLog.setTransactionId(notifyMap.get("transaction_id"));
        payLog.setPayType(1);
        payLog.setTradeState(notifyMap.get("result_code"));
        payLog.setAttr(new Gson().toJson(notifyMap));
        payLog.setPayTime(new Date());
        baseMapper.insert(payLog);
    }
}
